<?php 
/**
 * 汽车管理模型
 */
namespace Qwadmin\Model;
use Think\Model;
class CarModel extends Model{
    /**
     *  查看汽车状态 当前车辆是否可用
     * @param  [int] $car_id [汽车主键id]
     * @return [boolean]     [可用返回true ，否则返回false]
     */
    public function status($car_id = 0,$coach_id = 0){
        $id = (int)$car_id ? $car_id : 0;
        $co_id = (int)$coach_id ? $coach_id : 0;
        if(!$id) return false;
        if($co_id){
            
            $coach = D('coach');
            $coach_data = $coach->alias(' as co')->field('co.id,ca.status')->join(' driving_car as ca on co.car_id = ca.id')->where('co.id = '.$co_id.' and ca.id = '.$id)->find();
            if($coach_data){
                $status = $coach_data['status'];
                if($status == 1){
                    return true;
                }else{
                    return false;
                }
            }else{
                return false;
            }
        }else{
            $res = $this->find($id);
            // return $this->getLastSql();
            if($res){
                $status = $res['status'];
                if($status == 0){
                    return true;
                }elseif($status == 1){
                    return false;
                }else{
                    return false;
                }
            }else{
                return false;
            }
        }
    }
}
?>